﻿using System.Web.UI;
using System.Web;
using System;
using curbside.Web.UI.Script;

namespace curbside.Extensions
{
    public static class PageExtension
    {
        #region regist javascript operation

        /// <summary>
        /// 弹出alert对话框提示信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg">提示信息</param>
        public static void Prompt(this Page page, string msg)
        {
            PageClientScript.Prompt(msg);
        }

        /// <summary>
        /// 打开新窗口
        /// </summary>
        /// <param name="page"></param>
        /// <param name="url">新窗口url地址</param>
        public static void OpenNewWindow(this Page page, string url)
        {
            PageClientScript.OpenNewWindow(url);
        }

        /// <summary>
        /// 弹出alert对话框提示信息后跳转到指定页面
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转url地址</param>
        public static void PromptAndRedirect(this Page page, string msg, string url)
        {
            PageClientScript.PromptAndRedirect(msg, url);
        }

        /// <summary>
        /// 弹出alert对话框提示信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg">提示信息</param>
        /// <param name="autoClose"></param>
        public static void Prompt(this Page page, string msg, bool autoClose)
        {
            PageClientScript.Prompt(msg, autoClose);
        }

        /// <summary>
        /// 弹出alert对话框提示信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg">提示信息</param>
        /// <param name="autoClose">是否自动关闭</param>
        /// <param name="count">自动关闭时间</param>
        public static void Prompt(this Page page, string msg, bool autoClose, int count)
        {
            PageClientScript.Prompt(msg, autoClose, count);
        }

        #endregion

        #region string encode/decode

        /// <summary>
        /// 对URL字符串进行编码
        /// </summary>
        /// <param name="page"></param>
        /// <param name="str">要编码的文本</param>
        /// <returns></returns>
        public static string UrlEncode(this Page page, string str)
        {
            return HttpUtility.UrlEncode(str);
        }

        /// <summary>
        /// 将已经为在 URL 中传输而编码的字符串转换为解码的字符串。
        /// </summary>
        /// <param name="page"></param>
        /// <param name="str">要解码的字符串。</param>
        /// <returns></returns>
        public static string UrlDecode(this Page page, string str)
        {
            return HttpUtility.UrlDecode(str);
        }

        /// <summary>
        /// 对 URL 字符串的路径部分进行编码，以进行从 Web 服务器到客户端的可靠的 HTTP 传输。
        /// </summary>
        /// <param name="page"></param>
        /// <param name="str">要进行 URL 编码的文本。</param>
        /// <returns></returns>
        public static string UrlPathEncode(this Page page, string str)
        {
            return HttpUtility.UrlPathEncode(str);
        }

        /// <summary>
        /// 将字符串转换为 HTML 编码的字符串。
        /// </summary>
        /// <param name="page"></param>
        /// <param name="str">要编码的字符串。</param>
        /// <returns></returns>
        public static string HtmlEncode(this Page page, string str)
        {
            return HttpUtility.HtmlEncode(str);
        }

        /// <summary>
        /// 将已经为 HTTP 传输进行过 HTML 编码的字符串转换为已解码的字符串。
        /// </summary>
        /// <param name="page"></param>
        /// <param name="str">要解码的字符串。</param>
        /// <returns></returns>
        public static string HtmlDecode(this Page page, string str)
        {
            return HttpUtility.HtmlDecode(str);
        }

        #endregion

        #region ajaxpro

        public static void EnableAjaxPro(this Page page, Type type)
        {
            PageClientScript.EnableAjaxPro(type);
        }

        #endregion
    }
}
